﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpObjects.Configuration;
using SharpObjects.Configuration.ConfigurationProviders;
using SharpObjects.Configuration.Services;
using SharpObjects.EventBus;
using SharpObjects.Instantiation.Services;
using SharpObjects.Logging;
using SharpObjects.Shared;
using SharpObjects.Shared.ApplicationEvents;
using SharpObjects.Shared.Proxies;

namespace SharpObjects.Logging_Test
{


    class Logging_Test
    {
        static void Main(string[] args)
        {
            IConfigurationProvider config = new XmlConfigurationProvider("SharpObjects.Logging_test.config");
            ServiceFactory.Instance = config.GetObject<IServiceFactory>("/configuration/services");


            //ILogTarget textLogTarget = ServiceFactory.Instance.GetService<ILogTarget>("text_file_log_target");
            //ILogTarget consoleLogTarget = ServiceFactory.Instance.GetService<ILogTarget>("console_log_target");

            //ILogCategory debugCategory = ServiceFactory.Instance.GetService<ILogCategory>("DEBUG");

            //debugCategory.Write(new Origin("Logging_Test.Main()"), "Test message {0}", 1);

            IEventBus defaultEventBus = ServiceFactory.Instance.GetService<IEventBus>("default_event_bus");
            IEventBus logEventBus = ServiceFactory.Instance.GetService<IEventBus>("log_event_bus");
            
            LogApplicationEvent logEvent = new LogApplicationEvent()
                                               {
                                                   CategoryName = LogCategoryName.DEBUG,
                                                   Message = "Test Message 2",
                                                   Origin = new Origin("Logging_Test.Main()")
                                               };
            logEventBus.Publish(logEvent);


            //ServiceFactoryGetServiceApplicationEvent getServiceApplicationEvent = new ServiceFactoryGetServiceApplicationEvent() { ServiceId = "log" };
            //defaultEventBus.Publish(getServiceApplicationEvent);
            //ILog log = getServiceApplicationEvent.GetService<ILog>();

            //ILog log = ServiceFactory.Instance.GetService<ILog>("log");

            ServiceFactoryProxy servideFactoryProxy = new ServiceFactoryProxy(defaultEventBus);

            ILog log = servideFactoryProxy.GetService<ILog>("log");
            log.Write(LogCategoryName.INFO, new Origin("Main()"), "Test message {0}", 3);

            LogProxy logProxy = new LogProxy(logEventBus);
            logProxy.Write(LogCategoryName.WARNING, new Origin("Main()"), "Test message {0}", 4 );
        }

    }
}
